package entityMapping.demo3.service;

import entityMapping.demo3.bean.Computer;
import entityMapping.demo3.bean.Machine;
import entityMapping.demo3.dao.BaseDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ComputerMachineServiceImpl implements ComputerMachineService {

    @Autowired
    private BaseDao<Computer> computerBaseDao;
    @Autowired
    private BaseDao<Machine> machineBaseDao;

    @Override
    public List<Computer> loadAllComputer() {
        return computerBaseDao.recover(Computer.class);
    }

    @Override
    public List<Machine> loadAllMachine() {
        return machineBaseDao.recover(Machine.class);
    }

    @Override
    public List<Machine> loadParams(String column, Object param) {
        return null;
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void insert(Computer computer, Machine machine) {
        computerBaseDao.save(computer);
        machineBaseDao.save(machine);
    }

    @Override
    public void delete(Computer computer) {
        computerBaseDao.delete(computer);
    }
}
